import {ECHART_COLOR} from '../../utils/color';

export const echartsOption = (chart, tooltipCallback, labelCallback, color = ECHART_COLOR) => {
    const {legend = {}, xAxis = [], yAxis = [], series = []} = chart;
    let seriesData = series;
    seriesData = seriesData.map(ele => {
        if (ele.type === 'pie') {
            ele.radius = '45%';
            ele.center = ['40%', '50%'];
            ele.label = {
                formatter(params) {
                    return labelCallback ? labelCallback(params) : null;
                }
            };
        }
        return ele;
    });
    const option = {
        color,
        tooltip: {
            formatter(params) {
                return tooltipCallback ? tooltipCallback(params) : null;
            }
        },
        legend: {
            ...legend,
            orient: 'vertical',
            left: 'right',
            top: 'middle',
            type: 'scroll',
            align: 'left'
        },
        xAxis,
        yAxis,
        series: seriesData
    };
    return option;
};
